from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import blobstore
import os
import database
import urllib

class PersonPicture(webapp.RequestHandler):
	def get(self, nick):
		person = database.Person.get_by_key_name(urllib.unquote(nick))
		if not person: self.error(404); return
		if not person.picture: self.error(404); return
		self.response.headers['Content-Type'] = "image/jpeg"
		self.response.out.write(person.picture)

application = webapp.WSGIApplication([
		('/pictures/people/(.+)', PersonPicture),
	],
	debug=True
)

def main():
	run_wsgi_app(application)

if __name__ == "__main__":
	main()
